package com.kbot.bot.gui;

import com.kbot.bot.debug.Debug;
import com.kbot.bot.gui.loader.AppletInstance;
import com.kbot.bot.bot.Bot;
import com.kbot.bot.accessors.Client;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.applet.Applet;

/**
 * Created by IntelliJ IDEA.
 * User: Jan Ove
 * Date: 29.jan.2009
 * Time: 16:58:36
 * To change this template use File | Settings | File Templates.
 */
public class GUI extends JFrame {
    public GUI(){
        super();
        initComps();
        this.setVisible(true);
        Debug.write(this, "KBot by Kosaki started.");
        botThread = new Thread(bot = new Bot(theApplet));
    }

    private void initComps(){
        DebugComponent = new JTextArea();
		debugScrollPane = new JScrollPane();
        contentPane = (JPanel)this.getContentPane();
        menuBar = new JMenuBar();

        this.setTitle("KBot by Kosaki");
		this.setSize(new Dimension(777, 725));
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        contentPane.setLayout(null);
        addComponent(contentPane, debugScrollPane, 3,515,770,174);
        debugScrollPane.setViewportView(DebugComponent);
        debugScrollPane.setAutoscrolls(true);
        DebugComponent.setEditable(false);



        // Add bot
        theApplet = AppletInstance.addNewBot("169");
		addComponent(contentPane, theApplet, 0, 0, 768, 510);

        this.setJMenuBar(menuBar);
        JMenu menu = new JMenu("Run");
        menuBar.add(menu);
        menu.getPopupMenu().setLightWeightPopupEnabled(false);    
        JMenuItem item = new JMenuItem("getState");
        item.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                runGameStateScript();
            }
        });
        menu.add(item);

    }

    public static JTextArea DebugComponent;
    private JScrollPane debugScrollPane;
    private JPanel contentPane;
    private JMenuBar menuBar;
    public Applet theApplet;

    public Thread botThread;
    public Bot bot;

    private void addComponent(Container container,Component c,int x,int y,int width,int height)
	{
		c.setBounds(x,y,width,height);
		container.add(c);
	}

    private void runGameStateScript(){
        bot.run();
    }
}
